from fastapi.responses import JSONResponse

from common.base.base_routers import get_custom_router
from services.control.api import ControlApi
from services.control.schemas.control_registers import ControlStates
from common.utils import make_literal

ctrl_api = ControlApi()
control_router = get_custom_router(ctrl_api, prefix='/control', tags=['control'])


@control_router.get('/set-control-state/', response_class=JSONResponse)
async def set_control_state(name: make_literal(ControlStates), state: bool):
    return await ctrl_api.set_control_state(name, state)


@control_router.get('/get-all-control-states/', response_class=JSONResponse)
async def get_all_control_states():
    return await ctrl_api.get_all_control_states()


@control_router.get('/get-control-state/', response_class=JSONResponse)
async def get_control_state(name: make_literal(ControlStates)):
    return await ctrl_api.get_control_state(name)
